package com.blog.controller;

import com.blog.domain.DTO.AddLinkDto;
import com.blog.domain.DTO.LinkListDto;
import com.blog.domain.DTO.LinkStatusDto;
import com.blog.domain.DTO.StatusDto;
import com.blog.domain.ResponseResult;
import com.blog.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content/link")
public class LinkController {

	@Autowired
	private LinkService linkService;

	/**友链分类查询
	 *
	 * @param pageNum
	 * @param pageSize
	 * @param linkListDto
	 * @return
	 */
	@GetMapping("/list")
	public ResponseResult linkList(Integer pageNum, Integer pageSize,
	                               LinkListDto linkListDto){
		return linkService.linkList(pageNum,pageSize,linkListDto);

	}

	/**新增友链
	 *
	 * @param addLinkDto
	 * @return
	 */
	@PostMapping
	public ResponseResult addLink(@RequestBody AddLinkDto addLinkDto){
		return linkService.addLink(addLinkDto);

	}


	/**根据id查询友链回显
	 *
	 * @param id
	 * @return
	 */
	@GetMapping("/{id}")
	public ResponseResult getLinkById(@PathVariable Long id){
		return linkService.getLinkById(id);
	}

	/**修改友链
	 *
	 * @param addLinkDto
	 * @return
	 */
	@PutMapping
	public ResponseResult updateLink(@RequestBody AddLinkDto addLinkDto){
			return linkService.updateLink(addLinkDto);

	}

	/**删除友链
	 *
	 * @param ids
	 * @return
	 */
	@DeleteMapping("/{id}")
	public ResponseResult deleteLink(@PathVariable("id") List<Long> ids){

		return linkService.deleteLink(ids);
	}

	/**更新友链状态
	 *
	 * @param statusDto
	 * @return
	 */
	@PutMapping("/changeLinkStatus")
	public ResponseResult updateLinkStatus(@RequestBody LinkStatusDto linkStatusDto){

		return linkService.updateLinkStatus(linkStatusDto);


	}

}
